home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dc1 / pragma.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  4KB  |  202 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  PRAGMA.C
  9.  */
  10.  
  11. /*
  12. **      $Filename: pragma.c $
  13. **      $Author: dice $
  14. **      $Revision: 30.0 $
  15. **      $Date: 1994/06/10 18:04:52 $
  16. **      $Log: pragma.c,v $
  17.  * Revision 30.0  1994/06/10  18:04:52  dice
  18.  * .
  19.  *
  20.  * Revision 1.2  1993/09/06  09:56:47  jtoebes
  21.  * Fixed BUG65021 - #pragma libcall required 00 instead of just 0
  22.  *
  23. **/
  24.  
  25. #include "defs.h"
  26.  
  27. Prototype void ProcessLibCallPragma(char *, short);
  28. Prototype char *plcsym(char *, char **, short *);
  29. Prototype PragNode *TestPragmaCall(Var *, char *);
  30.  
  31. #define HSIZE    256
  32. #define HMASK    (HSIZE-1)
  33.  
  34.  
  35. PragNode *PragHash[HSIZE];
  36.  
  37. /*
  38.  *  DOSBase Open 1E 2102
  39.  *
  40.  *  Tag existing prototype with __libcall and store pragma in separate
  41.  *  semantic symbol table.  On procedure call this table will be searched
  42.  *  and the pragma decoded at that time
  43.  */
  44.  
  45. #ifdef REGISTERED
  46.  
  47. void
  48. ProcessLibCallPragma(char *buf, short syscall)
  49. {
  50.     PragNode *pn = zalloc(sizeof(PragNode));
  51.  
  52.     {
  53.     char *ptr = buf;
  54.  
  55.     if (syscall) {
  56.         pn->pn_Sym = PragmaSymbol("SysBase", 7);
  57.     } else {
  58.         short len;
  59.         char *name;
  60.  
  61.         ptr = plcsym(ptr, &name, &len);
  62.         pn->pn_Sym = PragmaSymbol(name, len);
  63.     }
  64.     ptr = plcsym(ptr, &pn->pn_Func, &pn->pn_FuncLen);
  65.     ptr = plcsym(ptr, &pn->pn_Off, &pn->pn_OffLen);
  66.     ptr = plcsym(ptr, &pn->pn_Ctl, &pn->pn_CtlLen);
  67.  
  68.     /*
  69.  
  70.     if (pn->pn_Sym->Data == NULL) {
  71.         Exp *exp = zalloc(sizeof(Exp) + sizeof(Stor));
  72.         pn->pn_Sym->Data = exp;
  73.         exp->ex_Func = FuncPragExp;
  74.         exp->ex_Type = &VoidPtrType;
  75.         AllocExternalStorage(pn->pn_Sym, (Stor *)(exp + 1), &VoidPtrType, (SmallData) ? TF_NEAR : TF_FAR);
  76.         printf("\txref\t_%.*s\n", pn->pn_Sym->Len, pn->pn_Sym->Name);
  77.     }
  78.  
  79.     */
  80.     }
  81.     {
  82.     PragNode **ppn = PragHash + (hash(pn->pn_Func, pn->pn_FuncLen) & HMASK);
  83.  
  84.     pn->pn_Next = *ppn;
  85.     *ppn = pn;
  86.     }
  87. }
  88.  
  89. char *
  90. plcsym(ptr, pbase, plen)
  91. char *ptr;
  92. char **pbase;
  93. short *plen;
  94. {
  95.     while (*ptr == ' ' || *ptr == '\t')
  96.     ++ptr;
  97.     *pbase = ptr;
  98.     while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n' && *ptr)
  99.     ++ptr;
  100.     *plen = ptr - *pbase;
  101.     return(ptr);
  102. }
  103.  
  104. #endif
  105.  
  106. PragNode *
  107. TestPragmaCall(var, prgno)
  108. Var *var;    /*  variable (procedure name) to test..      */
  109. char *prgno;    /*  array of 16 chars to be filled if 1 returned */
  110. {
  111.     PragNode *pn;
  112.  
  113.     {
  114.     Symbol *sym = var->Sym;
  115.     for (pn = PragHash[hash(sym->Name, sym->Len) & HMASK]; pn; pn = pn->pn_Next) {
  116.         if (sym->Len == pn->pn_FuncLen && cmpmem(sym->Name, pn->pn_Func, sym->Len) == 0)
  117.         break;
  118.     }
  119.     }
  120.     if (pn) {
  121.     char *ptr;
  122.     short i;
  123.     short j;
  124.     short narg = strtol(pn->pn_Ctl + pn->pn_CtlLen - 1, NULL, 16);
  125.  
  126.     if (pn->pn_Ctl[pn->pn_CtlLen-2] != '0')
  127.     {
  128.         if (pn->pn_Ctl[pn->pn_CtlLen-2] != ' ')
  129.         yerror(var->LexIdx, EFATAL_PRAGMA_RETURN_D0, pn->pn_FuncLen, pn->pn_Func);
  130.         pn->pn_Ctl[pn->pn_CtlLen-2] = '0';
  131.     }
  132.  
  133.     if (var->Type->Args != narg)
  134.         yerror(var->LexIdx, EFATAL_PRAGMA_CONFLICT_ARGS, pn->pn_FuncLen, pn->pn_Func);
  135.  
  136.     /*printf(";narg = %d\n", narg);*/
  137.     if (narg > 15)
  138.         narg = 15;
  139.  
  140.     if (pn->pn_Offset == 0)
  141.         pn->pn_Offset = strtol(pn->pn_Off, NULL, 16);
  142.  
  143.     ptr = pn->pn_Ctl;
  144.     for (i = 0, j = pn->pn_CtlLen - 3; i < narg; ++i, --j) {
  145.         short regNo = (j >= 0) ? pn->pn_Ctl[j] : '0';
  146.  
  147.         switch(regNo) {
  148.         case '0':
  149.         case '1':
  150.         case '2':
  151.         case '3':
  152.         case '4':
  153.         case '5':
  154.         case '6':
  155.         case '7':
  156.         regNo -= '0';
  157.         break;
  158.         case '8':
  159.         case '9':
  160.         regNo = regNo - '8' + 16;
  161.         break;
  162.         case 'a':
  163.         case 'b':
  164.         case 'c':
  165.         case 'd':
  166.         case 'e':
  167.         case 'f':
  168.         regNo = regNo - 'a' + 18;
  169.         break;
  170.         case 'A':
  171.         case 'B':
  172.         case 'C':
  173.         case 'D':
  174.         case 'E':
  175.         case 'F':
  176.         regNo = regNo - 'A' + 18;
  177.         break;
  178.         default:
  179.         regNo = 0;
  180.         }
  181.         prgno[i] = regNo;
  182.         /*printf(";argno %d regno %d\n", i, regNo);*/
  183.     }
  184.     prgno[i++] = RB_A6;
  185.  
  186.     while (i < 16) {
  187.         prgno[i] = -1;
  188.         ++i;
  189.     }
  190.  
  191.     /*
  192.      *  If our special pragma exp node has not been appended,
  193.      *  append one.
  194.      */
  195.  
  196.     return(pn);
  197.     } else {
  198.     return(NULL);
  199.     }
  200. }
  201.  
  202.